package com.zhangxiaofanfan.hotcode.second;

import java.util.HashSet;
import java.util.Set;

/**
 * TODO
 *
 * @author zhangxiaofanfan
 * @date 2024-05-24 17:07:19
 */
public class HotCode017 {
    public static void main(String[] args) {
        // int[] nums = {9, 2, 3, 8};
        int[] nums = {1,2,3,4};
        HotCode017 hotCode017 = new HotCode017();
        System.out.println(hotCode017.firstMissingPositive(nums));
    }

    public int firstMissingPositive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (num > 0 && num <= nums.length) {
                set.add(num);
            }
        }
        for (int i = 1; i <= nums.length; i++) {
            if (!set.contains(i)) {
                return i;
            }
        }
        return nums.length + 1;
    }
}
